<template>
  <div>
    <h1>当前求和为：{{ sum }}</h1>
    <h3>当前求和放大10倍为：{{ bigSum }}</h3>
    <h3>下方组件的总人数：{{ personList.length }}</h3>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="add(n)">+</button>
    <button @click="sub(n)">-</button>
    <button @click="addOdd(n)">当前是奇数再加</button>
    <button @click="addWait(n)">等一等再加</button>
  </div>
</template>

<script>
import { mapState, mapGetters, mapActions, mapMutations } from "vuex";
export default {
  name: "CalCount",
  data() {
    return {
      n: 1, //用户选择数字
    };
  },
  methods: {
    /* add() {
      // this.sum += this.n;
      this.$store.commit("ADD", this.n);
    },
    sub() {
      // this.sum -= this.n;
      this.$store.commit("SUB", this.n);
    },
    addOdd() {
      // this.sum % 2 == 0 ? this.sum : (this.sum += this.n);
      this.$store.dispatch("addOdd", this.n);
    },
    addWait() {
      this.$store.dispatch("addWait", this.n);
    }, */
    ...mapActions("countAbout", ["addOdd", "addWait"]),
    ...mapMutations("countAbout", { add: "ADD", sub: "SUB" }),
  },
  computed: {
    ...mapState("countAbout", ["sum"]),
    ...mapState("personAbout", ["personList"]),
    ...mapGetters("countAbout", ["bigSum"]),
  },
};
</script>

<style>
button {
  margin: 5px;
}
</style>